package com.googlecode.lohr.parser.combinators.matcher;

import com.googlecode.lohr.parser.combinators.MatchError;
import com.googlecode.lohr.parser.combinators.node.AbstractNode;

/**
 * Wraps the results from one matcher as results from another matcher.  
 * @author Ted Stockwell
 *
 */
public class WrappedMatchTask implements MatchListener {
	
	protected Matcher destinationMatcher;
	protected Matcher wrappedMatcher;
	protected MatchContext ctx;
	protected int start;
	public WrappedMatchTask(MatchContext ctx, Matcher destinationMatcher, Matcher wrappedMatcher, int start) {
		this.destinationMatcher= destinationMatcher;
		this.wrappedMatcher= wrappedMatcher;
		this.ctx= ctx;
		this.start= start;
	}

	@Override
	public void onMatchFound(AbstractNode match) {
		ctx.matchFound(destinationMatcher, start, match);
	}

	@Override
	public void onMatchComplete(MatchError matchError) {
		ctx.matchComplete(destinationMatcher, start, matchError);
	}
	
	public void run() {
		ctx.doMatch(wrappedMatcher, start, this);
	}
	
}
